package com.aofeng.hybridwork.application;

import android.app.Service;
import android.content.Intent;
import android.os.Environment;

import com.aofeng.hybrid.android.receiver.PhoneStatusReceiver;
import com.aofeng.hybrid.application.AFApplication;
import com.aofeng.hybrid.util.CommUtil;
import com.aofeng.hybrid.util.LogUtil;
import com.aofeng.hybridwork.android.service.TickService;
import java.io.File;
import java.net.URLEncoder;

public class HybridApplication  extends AFApplication {
		public static String WWW_BASE = "http://61.134.61.238:8002/cr/";
//	public static String WWW_BASE = "http://192.168.30.213:8082/cr/";
	public static String BASE_URL = WWW_BASE + "rs";

	public static String ENTITY_SERVICE_URL = BASE_URL + "/entity/";
	public static String SQL_SERVICE_URL = BASE_URL + "/sql/";
	public static String LOGIC_SERVICE_URL = BASE_URL + "/logic/";

	//元数据和网站同步所用地址
	public static String LOCAL_PATH_PREFIX = "file:///data/data/com.aofeng/";
		public static String REMOTE_WWW_PREFIX = "d:\\apk\\";
	public static String REMOTE_BZ_PREFIX = "D:\\Tomcat8\\webapps\\cr\\WEB-INF\\classes\\";
//	public static String REMOTE_WWW_PREFIX = "C:\\Users\\Administrator\\git\\cp\\product\\check\\VueWork\\dist\\";
//	public static String REMOTE_BZ_PREFIX = "C:\\Users\\Administrator\\git\\cp\\ShaanXiGas_SafetyCheck\\RestWork\\src\\test\\resources\\";
	public static String DIR_LIST_SERVICE_URL = BASE_URL + "/dir?path=";
	public static String DB_META_SERVICE_URL = BASE_URL + "/db/meta/";
	public static String FILE_SERVICE_URL = BASE_URL + "/dir/";
	public static String UPDATE_SERVICE_URL = BASE_URL + "/db/one/" + URLEncoder.encode("from t_singlevalue where name='hybrid_version'").replace("+", "%20");

    public static String APP_ID;

	//基准时间 20秒
	public static int BASE_INTERVAL = 1 * 20 * 1000;
	//5分钟上报一次状态
	public static int STATUS_COUNTER = 15;
    //背景服务引用
	public static Service service;

	public void onCreate() {
		super.onCreate();

		//基准时间
		BASE_INTERVAL = 1 * 20 * 1000;
		//3倍报警时间
		STATUS_COUNTER = 6;

		LOCAL_PATH_PREFIX = getFilesDir().getAbsolutePath()+ File.separator;

        APP_ID = this.getApplicationInfo().packageName;

		//创建目录，存资源
		APP_DATA = Environment.getExternalStorageDirectory()+ File.separator + "safecheck" + File.separator;
		File dir = new File(APP_DATA);
		if(!dir.exists())
			dir.mkdirs();

		//初始化接收器
		PhoneStatusReceiver psr = new PhoneStatusReceiver(this.getApplicationContext());
		psr.setupReceivers();

		//启动背景服务
		LogUtil.e("应用", "启动背景服务");
		Intent intent = new Intent(this, TickService.class);
		startService(intent);
    }

}
